package cloud.lysky.product.controller;

import cloud.lysky.product.service.IProductService;
import cloud.lysky.product.domain.Product;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/api/product")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ProductController {

    private final IProductService productService;

    @GetMapping("/{productId}")
    public Product getProduct(@PathVariable Long productId, HttpServletRequest request) {
        log.warn("{}:Fetching product data for id: {}", LocalDateTime.now(), productId);
        log.warn("Request Headers: {}", request.getHeader("Authorization"));
        log.warn("X-Custom-Header: {}", request.getHeaders("X-Custom-Header"));
        return productService.getById(productId);
    }

}
